home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
emulator
/
bsvc-1.000
/
bsvc-1
/
bsvc-1.0.4
/
src
/
Assemblers
/
hecasm
/
asm.h
next >
Wrap
C/C++ Source or Header
|
1995-07-26
|
6KB
|
207 lines
/* asm.h constants and type decarations */
#include <stdio.h>
#include <ctype.h>
#define NCPS 32 /* Characters per symbol */
#define CLMAX 100 /* Code bytes, line */
#define CBMAX 8 /* Code bytes, object */
#define USERMAX 512 /* User names 512 or 2048! */
#define SRCMAX 128 /* Source line length */
#define ERRMAX 4 /* Maximum errors per line */
#define REFMAX 4000 /* Maximum reference entries */
#define LREFMAX 16 /* References per listing line */
#define MAXADR 0X10000
#define TRUE -1
#define FALSE 0
#define WORD 0x0ffff
#define BYTE 0x0ff
/* The next constant is important. Much of this assembler is keyed on it
* It determines the fundamental word size of a machine. It is 1
* for byte, and 2 for word. This constant determines what size word
* is coded by codew(), and output by cflush() and outlisting(). */
#define WSIZE 2 /* number of bytes in machine word */
/* default radixes */
#define HEX 0
#define DEC 1
#define OCT 2
#define BIN 3
/*
* Reference chain structure
*/
struct reflst {
int r_stmtno; /* The statement number */
struct reflst *r_chain; /* Chain pointer */
};
/*
* Symbol table structure.
* Used in both the user symbol table and
* the opcode table.
*/
struct sym {
char s_name[NCPS]; /* Name */
char s_type; /* Type (pst only)*/
char s_flag; /* Some flags (ust only)*/
struct reflst *s_ref; /* Reference chain pointer (ust only)*/
int s_value; /* Value */
int s_used; /* valid flag (ust only)*/
};
/*
Instruction operand structures:
*/
/* Data:
This data structure contains the parsing information for the
data fields of HECTOR instructions. Each data field includes
1) the addressing mode of the operand,
2) the actual binary pattern of the specifying addressing
mode,
3) the register number implied (used) by the operand, and
4) the extension word, if any. */
struct d_operand
{
int mode; /* Addressing mode */
int mode_bits; /* Bit pattern of mode */
int reg; /* Bit pattern of register */
int ext_word; /* Value of extension word, if any */
int parse_error; /* Flag: 1=error; 0=OK */
};
/* Branch:
This data structure contains the parsing information for branch
condition codes. There are 16 branch conditions. */
struct b_operand
{
int mode_bits; /* Bit pattern of branch condition */
int parse_error; /* Flag: 1=error; 0=OK */
};
/*
* Types.
*/
/* These types are very important. They are stored in the permanent
* symbol table and determine how a statement will be handled in
* asm2.c. Types should also be added here for the opcodes to be
* included in the instruction set of this assembler. Group the
* instructions into classes to be handled the same (ie. two operand
/* instructions with the same addressing modes) */
#define GR_ORG 0 /* .org */
#define GR_PASCII 1 /* .ascii */
#define GR_LIST 2 /* .list pseudo-op */
#define GR_UASCII 3 /* .uascii */
#define GR_WORD 4 /* .word */
#define GR_BYTE 5 /* .byte */
#define GR_RMW 6 /* .blkb */
#define GR_RMB 7 /* .blkb */
#define GR_ONOFF 8 /* on-off flag */
#define GR_RADIX 9 /* .radix */
#define GR_END 10 /* .end */
#define GR_FMT1 11 /* dual operand */
#define GR_FMT2 12 /* single operand */
#define GR_FMT3 13 /* bra and jsr */
#define GR_FMT4 14 /* implied (no operand) */
#define GR_FMT5 15 /* push */
#define GR_FMT6 16 /* exch */
#define GR_FMT7 17 /* srch */
#define GR_FMT8 18 /* move */
#define GR_REG 19 /* registers */
#define GR_CC 81 /* condition codes */
#define GR_EQU 82 /* .equ directive */
/*
* addressing modes
*/
#define AM_RD 0 /* register direct */
#define AM_IN 1 /* indirect */
#define AM_IP 2 /* indirect w/post-inct */
#define AM_IX 3 /* indexed */
#define BM_R 23 /* register indirect */
#define BM_A 24 /* absolute */
#define BM_L 25 /* relative */
#define BM_I 26 /* indexed */
/* flags used inside the assembler */
#define SF_MDF 01 /* Multiply defined */
#define SF_ASG 02 /* Defined by assignment */
#define S_UND 00 /* Undefined */
#define S_ABS 01 /* Absolute */
#define S_VALID 02 /* defined */
#define S_DEF 04 /* defined pass 2 */
/* listing flags */
#define NOCODLIS 0
#define EMPTYLIS 1
#define ALLLIS 2
/* tables */
extern struct sym pst[]; /* Opcode table */
extern struct sym ust[]; /* User symbols */
extern struct reflst reftab[]; /* Reference list */
extern int pstsize; /* End of pst */
extern struct reflst *refptr; /* End of Reference table */
/* files */
extern FILE *ifp; /* Source */
extern FILE *lfp; /* Listing */
extern FILE *ofp; /* Object */
extern int radix; /* default radix */
/* flags */
extern int lflag; /* -l flag */
extern int nflag; /* -n flag */
/* position */
extern int pass; /* Which pass? */
extern int lineno; /* Line number */
/* line assembly */
extern int opcode; /* instuction opcode */
/* buffers */
extern char *sptr; /* Source pointer */
extern char sbuf[]; /* Source buffer */
extern int *cptr; /* Listing code pointer */
extern int cbuf[]; /* Listing code buffer */
extern char *eptr; /* Error pointer */
extern char ebuf[]; /* Error buffer */
extern int cadr; /* object line address */
extern int crec; /* next object word */
extern int crbf[CBMAX]; /* object code buffer */
extern int refcnt; /* Count of references */
extern struct sym *dot; /* location counter */
/* listing flags */
extern int listmode;
extern int listaddr;
/*
* Functions.
*/
extern struct sym *ustlookup(); /* Search */
extern struct sym *pstlookup(); /* Search */